package com.webcash.CNBoard.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.SqlSession;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.stereotype.Repository;

import com.webcash.CNBoard.Model.Schedule;
import com.webcash.CNBoard.Model.ScheduleMonthly;

@Repository
public class ScheduleRepositoryImpl extends SqlSessionDaoSupport implements ScheduleRepository {

	public List<Schedule> selectScheduleListByEmpNo(int empNo) {
		
		SqlSession session = getSqlSession();
		
		return session.selectList("Schedule.selectScheduleListByEmpNo", empNo);
	}

	public void insertScheduleByEmpNoAndSchedule(int empNo, Schedule schedule) {
		SqlSession session = getSqlSession();
		
		Map params = new HashMap();
		
		params.put("empNo", empNo);
		params.put("scheduleTitle", schedule.getScheduleTitle());
		params.put("scheduleContents", schedule.getScheduleContents());
		params.put("scheduleStartDate", schedule.getScheduleStartDate());
		params.put("scheduleEndDate", schedule.getScheduleEndDate());
		
		session.insert("Schedule.insertScheduleByEmpNoAndSchedule", schedule);
	}

	public void deleteScheduleByScheduleNo(int scheduleNo) {
		SqlSession session = getSqlSession();
		
		session.delete("Schedule.deleteScheduleByScheduleNo", scheduleNo);
	}

	public List<ScheduleMonthly> selectScheduleMonthlyListByEmpNo(int empNo) {
		SqlSession session = getSqlSession();
		
		return session.selectList("Schedule.selectScheduleMonthlyListByEmpNo", empNo);
	}

	public void insertScheduleMonthlyByEmpNoAndScheduleMonthly(int empNo,
			ScheduleMonthly scheduleMonthly) {
		SqlSession session = getSqlSession();
		
		Map params = new HashMap();
		System.out.println("this is the repository");
		params.put("empNo", empNo);
		params.put("scheduleTitle", scheduleMonthly.getScheduleTitle());
		params.put("scheduleContents", scheduleMonthly.getScheduleContents());
		params.put("startDate", scheduleMonthly.getStartDate());
		params.put("endDate", scheduleMonthly.getEndDate());
		params.put("everyWeekDay", scheduleMonthly.getEveryWeekDay());
		params.put("exceptWeekend", scheduleMonthly.isExceptWeekend());
		params.put("monthlyDay", scheduleMonthly.getMonthlyDay());
		
		
		System.out.println(scheduleMonthly);
		session.insert("Schedule.insertScheduleMonthlyByEmpNoAndScheduleMonthly", scheduleMonthly);
		
	}
	
	
}
